<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<title>三打二测试</title>
<script src="/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
    $(function(){
        var $text = $("#text")
        var $enterRoomBtn = $("#enter_room");
        var $sitdownBtn = $("#sitdownBtn");
        var $openBtn = $("#openBtn")
        var $callBtn = $("#callBtn")
        var $reBtn = $("#reBtn")
        var $zhuBtn = $("#zhuBtn")
        var $coverPokerBtn = $("#coverPokerBtn")
        var $zhuangBtn = $("#zhuangBtn")
        var $chupaiBtn = $("#chupaiBtn")
        
        var socket = io("127.0.0.1:32510"); //通过ip和端口建立一个socket client
        socket.on('connect', function(){
            console.log('connect a socket client');
        });
       
        $openBtn.click(function(){
            let userId = $text.val();
            socket.emit("open", {
                userId : +userId
            });
        })
        socket.on("open_result", function(data){
            console.log("-----open_result----");
            console.log(data);
        })
        //进入房间
        $enterRoomBtn.click(function(){
            let roomId = $text.val();
            socket.emit("user_enter",{
                roomId:roomId
            })
        })
        socket.on("user_enter_push", function(data){
            console.log("-------user_enter_push-----");
            console.log(data)
        });

        //坐下
        $sitdownBtn.click(function(){
            let value = $text.val();
            socket.emit("player_sit", JSON.parse(value))
        })

        socket.on("player_sit_push", function(data){
            console.log("player_sit_push");
            console.log(data);
        })

        //叫分
        $callBtn.click(function(){
            let value = $text.val();
            socket.emit("player_call",{
                score :+value
            });
        })
        socket.on("player_call_push", function(data){
            console.log(data)
        })

        //重连
        $reBtn.click(function(){
            socket.emit("recovery",{
            });
        })
        socket.on("request_connect_push", function(data){
            console.log(data);
        })

        //选主
        $zhuBtn.click(function(){
            let value = $text.val();
            socket.emit("select_zhu", {
                zhu :+value
            })
        })
        socket.on("select_zhu_push", handlerConsole)

        //埋牌
        $coverPokerBtn.click(function(){
            let value = $text.val();
            socket.emit("cover_poker", {
                pokers : JSON.parse(value)
            })
        })
        socket.on("cover_poker_push", handlerConsole);

        //选择副庄
        $zhuangBtn.click(function(){
            let value = $text.val();
            socket.emit("select_assistant", {
                poker : +value
            })
        })
        socket.on("game_result", handlerConsole)

        //出牌
        $chupaiBtn.click(function(){
            let value = $text.val();
            socket.emit("player_put", {
                pokers:[+value]
            })
        })
        socket.on("player_put_push", handlerConsole);
        function handlerConsole(data){
            console.log(data);
        }
    })
    
</script>
</head>
<body>
    <textarea id="text" style="width: 400px;"></textarea><br/>
    <input id="openBtn" type="button" value="open"/></br>
    <input id="enter_room" type="button" value="进入房间"></br>
    <input id="sitdownBtn" type="button" value="坐下" ></br>
    <input id="callBtn" type="button" value="叫分"></br>
    <input id="reBtn" type="button" value="重连"></br>
    <input id="zhuBtn" type="button" value="选主"></br>
    <input id="coverPokerBtn" type="button" value="埋牌"></br>
    <input id="zhuangBtn" type="button" value="选择副庄"></br>
    <input id="chupaiBtn" type="button" value="出牌"></br>
    <input id="exitBtn" type="button" value="离开房间"></br>
</body>
</html>
